package warehouse;

import java.util.ArrayList;

/**
 * OrderList class creates an array collection of order objects
 * 
 * @author Apeiranthitis, Grassos, Moschos
 * 
 */
public class OrderList implements Observer {
	// Collection for an arbitrary number of details.
	private ArrayList<Order> orderList;

	public ArrayList<Order> getOrderList() {
		return orderList;
	}

	/**
	 * Initializes the OrderList class constructor, creating a new ArrayList
	 * collection
	 */
	public OrderList() {
		orderList = new ArrayList<Order>();
	
     
	}

	/**
	 * Add a new set of details to the list
	 * 
	 * @param details
	 *            The details of the staff
	 */
	public void addDetails(Order details) {
		orderList.add(details);
	}

	/**
	 * Checks if the ArrayList collection is empty
	 * 
	 * @return boolean
	 */
	public boolean hasOrder() {
		return orderList.size() != 0;
	}

	/**
	 * Takes the next Order object from the OrderList, removing the one at the
	 * top (index = 0)
	 * 
	 * @return the order object
	 */
	public synchronized Order getNextOrder() {
		Order order = orderList.remove(0);
		return order;

	}

	/**
	 * Searches within the Order ArrayList
	 * 
	 * @return All the order ids
	 */
	public String listDetails() {
		StringBuffer allEntries = new StringBuffer();

		for (Order details : orderList) {
			allEntries.append(details.getOrderID() + " "
					+ details.getCustomerID() + " " + details.getItemID() + " "
					+ details.getOrderQuantity());
			allEntries.append('\n');
		}
		return allEntries.toString();
	}

	/**
	 * Checks whether the provided Order object`s ID already exists in our
	 * ArrayList
	 * 
	 * @param Order
	 *            object
	 * @return boolean
	 */
	public boolean checkEquality(Order o) {
		for (Order order : orderList) {
			if (o.equals(order)) {
				System.out.println("Order id: " + o.getOrderID()
						+ " already exists.");
				return true;
			}
		}
		return false;
	}

	public void update() {
		System.out.println("CHANGED ORDER");
	}

}
